package com.ama.controller;

import com.ama.pojo.Staff;
import com.ama.service.StaffService;
import com.ama.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
public class AddStaffController {

    @Autowired
    StaffService staffService;
    @RequestMapping("/AddStaff")
    public String AddStaff(HttpServletRequest request){

        Staff staff = new Staff();

        Long staffId = Long.valueOf(request.getParameter("staffId"));
        String password = request.getParameter("password");
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        String phone = request.getParameter("phone");
        String education = request.getParameter("education");
        String marriage = request.getParameter("marriage");
        String identity = request.getParameter("identity");
        String bankcard = request.getParameter("bankcard");
        String address = request.getParameter("address");
        String hukou = request.getParameter("hukou");
        String department = request.getParameter("department");
        String family = request.getParameter("family");
        Date entrytime = DateUtil.strToDate(request.getParameter("entrytime"));

        staff.setStaffId(staffId);
        staff.setStaffName(name);
        staff.setStaffPassword(password);
        staff.setGender(gender);
        staff.setStaffPhone(String.valueOf(phone));
        staff.setEducation(education);
        staff.setIdentity(String.valueOf(identity));
        staff.setBankcard(String.valueOf(bankcard));
        staff.setStaffAddress(address);
        staff.setHukou(hukou);
        staff.setMarriage(marriage);
        staff.setFamily(family);
        staff.setDepartment(department);
        staff.setEntrytime(entrytime);

        staffService.insert(staff);
        return "redirect:/success/AddStaff_suc.jsp";
    }
}
